ZXing - "Barcode Scanner"
=========================

Links:

	Zbar 
		https://github.com/dm77/barcodescanner		
	
	ZXing
		https://github.com/journeyapps/zxing-android-embedded
		https://github.com/journeyapps/zxing-android-embedded/tree/master/zxing-android-embedded
		https://github.com/zxing/zxing/wiki/Getting-Started-Developing
		http://mvnrepository.com/artifact/com.google.zxing
		https://github.com/journeyapps/zxing-android-embedded
		http://jcenter.bintray.com/com/journeyapps/
		
	Examples:
		http://stackoverflow.com/questions/4782543/integration-zxing-library-directly-into-my-android-application
		http://stackoverflow.com/questions/4854442/embed-zxing-library-without-using-barcode-scanner-app
		http://kvenkataprasad.blogspot.com.es/2015/01/bar-code-and-qr-code-scanner-example.html	
		http://karanbalkar.com/2013/12/tutorial-65-implement-barcode-scanner-using-zxing-in-android/
		http://stackoverflow.com/questions/4782543/integration-zxing-library-directly-into-my-android-application/34941618#34941618
			
			
Other QR reader libraries:
	https://github.com/hiteshsahu/XZing-Barcode-Scanner-Minified-Eclipse
	https://github.com/dlazaro66/QRCodeReaderView
		

Es un programa de escaneo que permite escanear códigos QR y de barras.

Los desarrolladores proveen de librerías para su uso dentro de una aplicación
Android. Se disponen de dos aproximaciones:

- Integración parcial. Este modelo requiere de un JAR de integración que lo que
hace al ser usado es lanzar la app si esta instalada para escanear, en caso de no
estarlo, se solicita su instalación. Una vez escanea la app el código de barras o 
QR se envía de vuelta a la app el resultado. Esta aproximación requiere de:

	* La librería "android-zxing-integration-3.1.0.jar"

- Integración total. En este modelo el escaneo se hace completamente in-app, sin 
necesidad de instalación de la app de "Barcode Scanner" de ZXing. Esta aproximación
requiere de:

	* La librería "zxing-core.3.2.0.jar"
	* Las librerías (recompiladas en el caso de Android 6+):
		- zbar.jar
		- Las liberías nativas "armeabi" (JNI, usando el NDK) de android:
		   * libiconv.so
		   * libzbarjni.so
	* Un activity que presente la cámara y en el que se use ZXING.


Recompilación de ZBAR
---------------------

There was a recent change in Android M that causes shared libraries built with text relocations 
to fail "to >load". App developers that are using barcodescanner (specifically, the 
zbar sub->module) cannot target API level 23 because the .so's included in barcodescanner get 
caught by this change. This is reported as issue #123 (https://github.com/dm77/barcodescanner/issues/123).

The fix is to rebuild these libraries with "position independent code", e.g., the cflag -fPIC.


1.- Descarga de la librería nativa de Android "libiconv":

	cd downloads/
	mkdir zbar
	cd zbar
	wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
	tar zxvf libiconv-1.14.tar.gz

2.- Configure de native library:
	
	cd libiconv-1.14/
	nano -c ./libcharset/lib/localcharset.c
	On line 48, add the following line of code:
		#undef HAVE_LANGINFO_CODESET	
	./configure

3.- Descargar la librería "zbar-code":

	cd ..
	Si no tenemos el Mercurial (cliente de GitHub) instalado:
		sudo apt-get install mercurial
	... Info: https://help.ubuntu.com/community/Mercurial
	hg clone http://hg.code.sf.net/p/zbar/code zbar-code	

4.- Descargar el SDK de Android:

	wget http://dl.google.com/android/android-sdk_r24.2-linux.tgz
	tar -xvf android-sdk_r24.2-linux.tgz
	Descargar las distribuciones de Android:
		./android-sdk-linux/tools/android update sdk --no-ui
	Listar las distribuciones instaladas:
		./android-sdk-linux/tools/android list targets

5.- Configurar la utilidad Ant:
	
	sudo apt-get install ant

6.- Instalar el Native Development Kit de Android (NDK)

	wget http://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip
	unzip android-ndk-r11c-linux-x86_64.zip	
	export NDK_HOME=/root/downloads/zbar/android-ndk-r11c
	echo $NDK_HOME

7.- Configurar el proyecto de ZBAR:
	
	cd zbar-code/android
	../../android-sdk-linux/tools/android update project -p . -t 'android-19'	
	(
		...info about "android" command
			https://developer.android.com/studio/tools/help/android.html?hl=ca
			https://spring.io/guides/gs/android/
			http://pof.eslack.org/2012/01/25/android-development-from-command-line/
	)
	
	Modify the files:
		Configure the LOCAL_CFLAGS:
			nano jni/Android.mk
			...modify "LOCAL_CFLAGS" variable to look like this:
			LOCAL_CFLAGS := \
			    -Wno-multichar \
			    -D_ANDROID \
			    -DLIBDIR=\"c\" \
			    -fPIC \
			    -DBUILDING_LIBICONV \
			    -DBUILDING_LIBCHARSET \
			    -DIN_LIBRARY
			
		Set the desired targets:
			nano jni/Application.mk
			... set like this: APP_ABI := armeabi armeabi-v7a x86

8.- Recompilar la librería:

	ant -Dndk.dir=$NDK_HOME -Diconv.src=/root/downloads/zbar/libiconv-1.14 zbar-clean zbar-all

	About the NDK:
		https://developer.android.com/ndk/guides/ndk-build.html?hl=es
		http://brian.io/android-ndk-r10c-docs/Programmers_Guide/html/md_3__key__topics__building__chapter_1-section_8_ndk-build.html

9.- Get the precompiled files at zbar/zbar-code/java/build